<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" style="top:5px;" title="用户权限清单列表" width="80%">
    <div>
      <el-input v-model="form.userParamBean.userAccount" clearable placeholder="输入账号搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="searchData"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="searchData">搜索</el-button>
      <el-button
        v-loading="exportLoading"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-download"
        @click="doExport"
      >导出</el-button>
    </div>
    <DataGridTable
      v-loading="loading"
      :data="privDataList"
      :show-page="false"
      :multi-select="false"
      :show-row-number="true"
      row-key="id">
      <el-table-column prop="ROLE_NAME" label="角色"/>
      <el-table-column prop="USER_ACCOUNT" label="账号"/>
      <el-table-column prop="USER_NAME" label="用户名称"/>
      <el-table-column prop="MENU_NAME" label="菜单名"/>
      <el-table-column prop="ORG_CODE" label="机构编号"/>
      <el-table-column prop="ORG_NAME" label="机构名称"/>
    </DataGridTable>
  </el-dialog>
</template>

<script>
import { findAllPrivList, exportUrl } from '@/api/system/role'
import { postRequestDownload } from '@/api/data'

export default {
  props: {
  },
  data() {
    return {
      privDataList: [],
      loading: false,
      dialog: false,
      exportLoading: false,
      form: {
        userParamBean: {
          userAccount: ''
        }
      }
    }
  },
  created() {
  },
  methods: {
    loadData() {
      this.searchData()
    },
    doExport() {
      this.$confirm('确认要导出?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.exportLoading = true
        const exportFileName = Date.parse(new Date()) + '.xlsx'
        postRequestDownload(exportUrl(), this.form, exportFileName).then(res => {
          this.exportLoading = false
        }).catch(err => {
          this.exportLoading = false
          console.log(err)
        })
      })
    },
    searchData() {
      this.loading = true
      findAllPrivList(this.form).then(res => {
        this.privDataList = res.data
        this.loading = false
      })
    }
  }
}
</script>
